class SpiralSrray {
	public int[] spiralArray(int[][] array) {
		if(array == null || array.length == 0 || array[0].length == 0){
			return new int[0];
		}
		int r = array.length;
		int c = array[0].length;
		int[] nums = new int[c * r];
		int index = 0;
		int left = 0;
		int top = 0;
		int right = c - 1;
		int bottom = r - 1;
		while(left <= right && top <= bottom){
			for(c = left ; c <= right ; c++){
				nums[index++] = array[top][c];
			}
			for(r = top + 1 ; r <= bottom ; r++){
				nums[index++] = array[r][right];
			}
			if(left < right && top < bottom){
				for(c = right - 1 ; c > left - 1 ; c--){
					nums[index++] = array[bottom][c];
				}
				for(r = bottom ; r > top ; r--){
					nums[index++] = array[r][left];
				}
			}
			top++;
			left++;
			right--;
			bottom--;
		}
		return nums;
	}
}